//
//  BiReturnManageViewController.m
//  TrunkIndustryManageSystem
//
//  Created by 李璐西 on 15-5-1.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//
static CGRect frame;
#import "BiReturnManageViewController.h"

@interface BiReturnManageViewController ()<UITextViewDelegate>{
    __weak IBOutlet UIScrollView *_ScrollView;
}
@property (weak, nonatomic) IBOutlet UILabel *labBorrowCarPerson;
@property (weak, nonatomic) IBOutlet UILabel *labVIN;
@property (weak, nonatomic) IBOutlet UILabel *labDirverName;
@property (weak, nonatomic) IBOutlet UILabel *labStoreroomManerName;
@property (weak, nonatomic) IBOutlet UILabel *labDriverPreformance;
@property (weak, nonatomic) IBOutlet UILabel *labStoreroomManerPreformance;
@property (weak, nonatomic) IBOutlet UILabel *labApplyPersonPerformance;
@property (weak, nonatomic) IBOutlet UILabel *labApplyDate;
@property (weak, nonatomic) IBOutlet UILabel *labReturnCarDate;
@property (weak, nonatomic) IBOutlet UILabel *labSumPerformance;
@property (weak, nonatomic) IBOutlet UITextView *textVjcReasons;
@property (weak, nonatomic) IBOutlet UILabel *labjcApprovePersonName;
@property (weak, nonatomic) IBOutlet UILabel *labhcHandlerName;
@property (weak, nonatomic) IBOutlet UILabel *labhcCheckDate;
@property (weak, nonatomic) IBOutlet UILabel *labapplyDate;
@property (weak, nonatomic) IBOutlet UITextView *textfRejectRSN;

@end

@implementation BiReturnManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavBackBtn];
    [self setNavBarTitle:@"还车审批"];
    [self setNavBarWithHidden:NO];
    
    
    self.textfRejectRSN.layer.borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:100.0].CGColor;
    self.textfRejectRSN.layer.borderWidth = 0.5;
    self.textVjcReasons.layer.borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:100.0].CGColor;
    self.textVjcReasons.layer.borderWidth = 0.5;
    _ScrollView.contentSize = CGSizeMake(MAIN_SCREEN_WIDTH, 680);
    [self dataFill];
     frame = _ScrollView.frame;
}

- (void)dataFill{
    if (self.returnManageEntity) {
        _labBorrowCarPerson.text = self.returnManageEntity.borrowCarPersonName;
        _labVIN.text = self.returnManageEntity.vin;
        _labDirverName.text = self.returnManageEntity.driverName;
        _labStoreroomManerName.text = self.returnManageEntity.storeroomMangerName;
        _labDriverPreformance.text = self.returnManageEntity.driverPreformance;
        _labStoreroomManerPreformance.text = self.returnManageEntity.storeroomMangerPreformance;
        _labApplyPersonPerformance.text = self.returnManageEntity.applyPersonPerformance;
        _labApplyDate.text = self.returnManageEntity.applyDate;
        _labReturnCarDate.text = self.returnManageEntity.returnCarDate;
        _labSumPerformance.text = self.returnManageEntity.sumPerformance;
        _textVjcReasons.text = self.returnManageEntity.jcResaon;
        _textfRejectRSN.text = self.returnManageEntity.hcRejecctReason;
        _labjcApprovePersonName.text = self.returnManageEntity.jcApprovePersonName;
        
        _labhcHandlerName.text = self.returnManageEntity.hcHandlerName;
        _labhcCheckDate.text = self.returnManageEntity.hcCheckDate;
        _labapplyDate.text = self.returnManageEntity.applyDate;
        
        if (self.returnManageEntity.hcCheckDate.length > 0) {
             _labhcCheckDate.text = self.returnManageEntity.hcCheckDate;
        }else{
            _labhcCheckDate.text = [BiUtil stringFromFomate:[NSDate date] formate:TIME_FOMTTER
                                    ];
        }
       
    }
}

- (IBAction)btnPermissionClick:(UIButton *)sender {
//    NSString * stutas = nil;
//    if (1 == sender.tag) {
//        //批准
//        stutas = @"1";
//    }else if (2 == sender.tag){
//        //驳回
//        stutas = @"0";
//    }
    NSString *hcApprovePersonId = nil;
    if (self.returnManageEntity.hcApprovePersonId.length != 0){
       hcApprovePersonId = self.returnManageEntity.hcApprovePersonId;
    }
    else{
       hcApprovePersonId = [BiUserEntity sharedInstance].userid;
    }
    NSDictionary *paraDic = [NSDictionary dictionaryWithObjectsAndKeys:
                             self.returnManageEntity.e_id,@"id",
                             @"1",@"status",
                             @"5",@"jcStatus",
                             hcApprovePersonId,@"hcApprovePersonId",
                             
                             [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:mm"],@"hcApproveDate",
//                             self.textfRejectRSN.text,@"hcRejectReason",
                             
                             self.returnManageEntity.hcHandlerId,@"hcHandlerId",
                             [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:mm"],@"hcCheckDate",
                             nil];
    NSLog(@"Permission%@",paraDic);
    [[BiNetEngine shareInstance] requestCarReturnCheck:self paraDict:paraDic];
    [self asyshowHUDView:WAITING CurrentView:self];
}

- (IBAction)btnRejectClick:(UIButton *)sender {
//    NSString *hcApprovePersonId = nil;
//    if (self.returnManageEntity.hcApprovePersonId == 0){
//        hcApprovePersonId = self.returnManageEntity.hcApprovePersonId;
//    }
//    else{
//        hcApprovePersonId = [BiUserEntity sharedInstance].userid;
//    }
    NSDictionary *paraDic = [NSDictionary dictionaryWithObjectsAndKeys:
                             self.returnManageEntity.e_id,@"id",
                             @"0",@"status",
                             @"5",@"jcStatus",
                             
//                             hcApprovePersonId,@"hcApprovePersonId",
//                             
//                             [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:mm"],@"hcApproveDate",
                             _textVjcReasons.text,@"hcRejecctReason",
                             
//                             self.returnManageEntity.hcHandlerId,@"hcHandlerId",
//                             [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:mm"],@"hcCheckDate",
                             nil];
//    NSLog(@"Reject%@",paraDic);
    [[BiNetEngine shareInstance] requestCarReturnCheck:self paraDict:paraDic];
    [self asyshowHUDView:WAITING CurrentView:self];
}

#pragma mark -textview delegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    if ([@"\n" isEqualToString:text] == YES)
    {
        [textView resignFirstResponder];
        
        
        return NO;
    }
    return YES;
}


- (void)textViewDidBeginEditing:(UITextView *)textView{
    frame= _ScrollView.frame;
    
    if (isIPhone4) {
        _ScrollView.frame = CGRectMake(0, _ScrollView.frame.origin.y - 200, _ScrollView.frame.size.width, _ScrollView.frame.size.height);
    }
}


- (void)textViewDidEndEditing:(UITextView *)textView{
    
    [textView resignFirstResponder];
    
    _ScrollView.frame = frame;
    
}



#pragma -mark Net Delegate
- (void)onNetEngineResponse:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    
    [self removeHUDView:self];
    
    NSDictionary * entity_ = (NSDictionary *)entity;
    
    [self showMessage:entity_[@"result_info"]];
    
    if ([entity_[@"response_status"] integerValue] != 200) {
        
        return;
        
    }
    
    switch (tag) {
        case NET_GET_CAR_RETURN_CHECK:
        {
            [self.navigationController popViewControllerAnimated:YES];
            
        }
            break;
            
        default:
            break;
    }
    
    
    
}
- (void)onNetEngineResponseFail:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    [self removeHUDView:self];
    
}

@end
